<template>
	<view class="signinform">
		<view class="title">现场验收信息系统</view>

		<view class="container">
			<view class="login-card">
				<!-- 背景装饰元素 -->
				<view class="decorator-circle circle-1"></view>
				<view class="decorator-circle circle-2"></view>

				<view class="login-header">
					<image class="logo" src="/static/logo.png" mode="aspectFit"></image>
					<view class="login-title">欢迎登录</view>
				</view>

				<!-- <view class="form-container">
					<view class="input-group">
						<image class="input-icon" src="/static/un.png"></image>
						<input class="input" type="password" v-model="verificationCode" placeholder="请输入个人身份校验码" />
					</view>
					<button class="login-btn" @click="login">登 录</button>
				</view> -->
			</view>
		</view>
	</view>
</template>

<script setup>

const token = uni.getStorageSync("userInfo").token;
if (token) {
	uni.request({
		url: './api/ct',
		method: 'GET',
		header: {
			'Authorization': `Bearer ${token}`
		},
		success: (res) => {
			if (res.statusCode === 200 && res.data.message === "合法") {
				uni.redirectTo({
					url: "/pages/TaskOverview",
				});
			}
		}
	})
}

import {
	ref
} from "vue";

// const verificationCode = ref("");

// const login = () => {
// 	if (!verificationCode.value) {
// 		uni.showToast({
// 			title: "请输入校验码",
// 			icon: "none",
// 		});
// 		return;
// 	}

// 企业号web网关请求
let usermobile
uni.request({
	url: "/@api_user_info/getUserInfo",
	method: "GET",
	success: (res) => {
		const veri = res.data
		if (veri.code === 10000) {
			usermobile = veri.value.UserMobile
			uni.request({
				url: "./api/applogin",
				method: "GET",
				data: {
					uniqueCode: usermobile,
				},
				success: (res) => {
					if (res.statusCode === 200 && res.data.message === '登录成功') {
						// console.log(res)
						uni.setStorageSync('userInfo', {
							name: res.data.name,
							token: res.data.access_token,
							role: res.data.role
						})

						uni.showToast({
							title: "登录成功",
							icon: "success",
						});

						uni.navigateTo({
							url: "/pages/TaskOverview",
						});
					} else {
						uni.showToast({
							title: res.data?.message || "登录失败",
							icon: "none",
						});
					}
				},
				fail: (err) => {
					console.error("请求失败：", err);
					uni.showToast({
						title: "网络错误，请重试",
						icon: "none",
					});
				},
			});
		} else {
			uni.navigateTo({
				url: "/pages/404",
			})
		}

	}

}
)
// uni.request({
// 	url: "./api/applogin",
// 	method: "GET",
// 	data: {
// 		uniqueCode: 18759900707,
// 	},
// 	success: (res) => {
// 		if (res.statusCode === 200 && res.data.message === '登录成功') {
// 			// console.log(res)
// 			uni.setStorageSync('userInfo', {
// 				name: res.data.name,
// 				token: res.data.access_token,
// 				role: res.data.role
// 			})

// 			uni.showToast({
// 				title: "登录成功",
// 				icon: "success",
// 			});

// 			uni.navigateTo({
// 				url: "/pages/TaskOverview",
// 			});
// 		} else {
// 			uni.showToast({
// 				title: res.data?.message || "登录失败",
// 				icon: "none",
// 			});
// 		}
// 	},
// 	fail: (err) => {
// 		console.error("请求失败：", err);
// 		uni.showToast({
// 			title: "网络错误，请重试",
// 			icon: "none",
// 		});
// 	},
// });

</script>

<style scoped lang="scss">
body,
html {
	margin: 0;
	padding: 0;
	overflow: hidden;
}

.signinform {
	background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
	min-height: 100vh;
	padding: 1rpx 40rpx;
	display: flex;
	flex-direction: column;
	justify-content: center;

	.title {
		font-size: 52rpx;
		color: #333;
		text-align: center;
		margin-bottom: 40rpx;
		font-weight: 500;
	}

	.container {
		display: flex;
		justify-content: center;
	}

	.login-card {
		background: white;
		border-radius: 24rpx;
		width: 90%;
		max-width: 600rpx;
		padding: 60rpx 40rpx;
		box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.1);
		position: relative;
		overflow: hidden;
		/* 防止内容溢出 */

		.container {
			height: 100vh;
			/* 确保容器高度不超过视口 */
			overflow: hidden;
			/* 隐藏可能的滚动 */
		}
	}

	.decorator-circle {
		position: absolute;
		border-radius: 50%;
		background: rgba(0, 122, 255, 0.1);

		&.circle-1 {
			width: 200rpx;
			height: 200rpx;
			top: -100rpx;
			right: -100rpx;
		}

		&.circle-2 {
			width: 300rpx;
			height: 300rpx;
			bottom: -150rpx;
			left: -150rpx;
		}
	}

	.login-header {
		text-align: center;
		margin-bottom: 40rpx; // 从60rpx减少到40rpx

		.logo {
			width: 120rpx;
			height: 120rpx;
			margin-bottom: 20rpx;
		}

		.login-title {
			font-size: 40rpx;
			color: #333;
			font-weight: 600;
			margin-bottom: 10rpx;
		}

		.login-subtitle {
			font-size: 28rpx;
			color: #999;
		}
	}

	.form-container {
		.input-group {
			display: flex;
			align-items: center;
			background: #f8f9fa;
			border-radius: 12rpx;
			padding: 0 20rpx;
			margin-bottom: 30rpx;
			border: 1rpx solid #eee;
			transition: all 0.3s;

			&:focus-within {
				border-color: #007aff;
				box-shadow: 0 0 0 2rpx rgba(0, 122, 255, 0.2);
			}

			.input-icon {
				width: 36rpx;
				height: 36rpx;
				margin-right: 20rpx;
			}

			.input {
				flex: 1;
				height: 80rpx;
				font-size: 30rpx;
				color: #333;
				background: transparent;

				&::placeholder {
					color: #bbb;
				}
			}
		}

		.form-actions {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 40rpx;

			.remember-me {
				display: flex;
				align-items: center;
				font-size: 26rpx;
				color: #666;

				checkbox {
					margin-right: 10rpx;
				}
			}

			.forgot-password {
				color: #007aff;
				font-size: 26rpx;
			}
		}

		.login-btn {
			width: 100%;
			height: 88rpx;
			background: linear-gradient(to right, #007aff, #0062cc);
			color: white;
			border-radius: 12rpx;
			font-size: 32rpx;
			font-weight: 500;
			border: none;
			box-shadow: 0 4rpx 12rpx rgba(0, 122, 255, 0.3);
			transition: all 0.3s;

			&:active {
				transform: translateY(2rpx);
				box-shadow: 0 2rpx 6rpx rgba(0, 122, 255, 0.3);
			}
		}
	}
}
</style>